//
//  JRUUID.swift
//  JRKeyChain
//
//  Created by 京睿 on 2017/6/9.
//  Copyright © 2017年 JingRuiWangKe. All rights reserved.
//

import Foundation

private class JRUUID {
    fileprivate static var value: String! {
        let ref = CFUUIDCreate(kCFAllocatorDefault)
        guard let uuid = CFUUIDCreateString(kCFAllocatorDefault, ref) as String? else { return nil }
        return uuid.replacingOccurrences(of: "-", with: "")
    }
}

extension JRKeyChain {
    private static let key = "uuid_value_key"
    
    public static var uuid: String! {
        if let foo = select(key) as? String {
            return foo
        } else {
            update(key, value: JRUUID.value)
            return select(key) as? String
        }
    }
}
